package com.sk.weichat.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.sk.weichat.R;
import com.sk.weichat.bean.message.ChatMessageEntity;
import com.sk.weichat.util.DateUtils;
import com.sk.weichat.view.SpaceItemDecoration;

import java.util.ArrayList;
import java.util.List;

public class SearchDesignationContentAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    List<ChatMessageEntity> mChatMessageEntity;
    Context context;
    private DesignationContentAdapter mDesignationContentAdapter;

    private String mSearchObject;
    public SearchDesignationContentAdapter(Context context,List<ChatMessageEntity> chatMessages,String mSearchObject) {
        if (mChatMessageEntity == null) {
            mChatMessageEntity = new ArrayList<>();
        }
        this.mChatMessageEntity = chatMessages;
        this.context =context;
        this.mSearchObject = mSearchObject;
    }
    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new SearchDesignationContentHolder(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.row_classify_image_video, viewGroup, false));
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
        ChatMessageEntity chatMessageEntity = mChatMessageEntity.get(position);
        String currentStr = DateUtils.getTodayYearMonthTimes();
        String dateStr = currentStr.equals(chatMessageEntity.getDateEntity())?"本月":chatMessageEntity.getDateEntity();
        ((SearchDesignationContentHolder) viewHolder).tv_date.setText(dateStr);
        mDesignationContentAdapter = new DesignationContentAdapter(context,chatMessageEntity.getmChatMessage(),mSearchObject);
        ((SearchDesignationContentHolder) viewHolder).recy_grid.setAdapter(mDesignationContentAdapter);
    }

    @Override
    public int getItemCount() {
        return mChatMessageEntity.size();
    }


    class SearchDesignationContentHolder  extends RecyclerView.ViewHolder{
        private TextView tv_date;
        private RecyclerView recy_grid;
        public SearchDesignationContentHolder(@NonNull View itemView) {
            super(itemView);
            tv_date = itemView.findViewById(R.id.tv_date);
            recy_grid = itemView.findViewById(R.id.recy_grid);
            recy_grid.setLayoutManager(new LinearLayoutManager(context));
        }
    }
}
